<template>
  <!-- 搜索组件 -->
  <div id="search">
    <div class="search-container">
      <div class="search-title">查询</div>
      <el-form :inline="true" class="demo-form-inline search">
        <div class="block">
          <span class="demonstration">日期范围</span>
          <el-date-picker v-model="value1" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
          </el-date-picker>
        </div>

        <!-- <el-button>每日</el-button>
        <el-button>每周</el-button>
        <el-button>每月</el-button> -->

        <el-form-item class="search-item">
          <el-button type="success" icon="el-icon-search" @click="onSearch">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import bus from '../EventBus'
export default {
  props: {
    getDataList: {
      type: Array,
      default: []
    },
    newCount: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      value1: ''
    }
  },
  methods: {
    //点击搜索的函数
    onSearch() {
      // console.log('submit!')
      //通过兄弟组件传值，将从父组件中获得的接口数据 传给兄弟组件 执行调用函数接口
      bus.$emit('getStoreData', this.getDataList, this.newCount, this.value1)
    }
  },
  //监听时间选择器中的值(value1)是否为null，如果为null，将该值赋值为空数组，并再次调用渲染列表函数
  watch: {
    value1(newVal, oldVal) {
      // console.log(newVal, oldVal)
      if (newVal == null) {
        this.value1 = []
        this.onSearch()
      }
    }
  }
}
</script>

<style lang="less" scoped>
.search-container {
  background-color: #fff;
  //   height: 8rem;
  border: 0.1rem solid #dbe0e9;
  .search-title {
    height: 4rem;
    background-color: #f2f2f2;
    box-sizing: border-box;
    border-bottom: 0.1rem solid #dbe0e9;
    line-height: 4rem;
    font-size: 1.4rem;
    padding-left: 3rem;
    font-weight: 500;
    color: #666666;
  }
  .search {
    display: flex;
    // flex-wrap: wrap;
    align-items: center;
    margin: 1rem;
    padding: 1.5rem;
    box-sizing: border-box;
    background-color: #f5f9fc;
    .el-form-item {
      margin-bottom: 0;
    }
    .dishes-name {
      margin-left: 1.5rem;
    }
    .block {
      margin-right: 2rem;
      .demonstration {
        font-size: 1.4rem;
        color: #606266;
        margin: 1.5rem;
      }
    }
  }
  .search-item {
    margin-left: 1.5rem;
  }
}
</style>
